package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.CureMethodDAO;
import cn.edu.scau.cmi.hombio.dao.CurePigDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskCourseDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskMethodDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;

import cn.edu.scau.cmi.hombio.domain.CureMethod;
import cn.edu.scau.cmi.hombio.domain.CurePig;
import cn.edu.scau.cmi.hombio.domain.CureTaskCourse;
import cn.edu.scau.cmi.hombio.domain.CureTaskMethod;
import cn.edu.scau.cmi.hombio.domain.Task;

import cn.edu.scau.cmi.hombio.service.CureTaskCourseService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for CureTaskCourse entities
 * 
 */

@Controller("CureTaskCourseRestController")

public class CureTaskCourseRestController {

	/**
	 * DAO injected by Spring that manages CureMethod entities
	 * 
	 */
	@Autowired
	private CureMethodDAO cureMethodDAO;

	/**
	 * DAO injected by Spring that manages CurePig entities
	 * 
	 */
	@Autowired
	private CurePigDAO curePigDAO;

	/**
	 * DAO injected by Spring that manages CureTaskCourse entities
	 * 
	 */
	@Autowired
	private CureTaskCourseDAO cureTaskCourseDAO;

	/**
	 * DAO injected by Spring that manages CureTaskMethod entities
	 * 
	 */
	@Autowired
	private CureTaskMethodDAO cureTaskMethodDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CureTaskCourse entities
	 * 
	 */
	@Autowired
	private CureTaskCourseService cureTaskCourseService;

	/**
	 * Show all CureMethod entities by CureTaskCourse
	 * 
	 */
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureMethods", method = RequestMethod.GET)
	@ResponseBody
	public List<CureMethod> getCureTaskCourseCureMethods(@PathVariable Integer curetaskcourse_id) {
		return new java.util.ArrayList<CureMethod>(cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id).getCureMethods());
	}

	/**
	* View an existing CurePig entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/curePigs/{curepig_id}", method = RequestMethod.GET)
	@ResponseBody
	public CurePig loadCureTaskCourseCurePigs(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curepigs_id) {
		CurePig curepig = curePigDAO.findCurePigByPrimaryKey(related_curepigs_id, -1, -1);

		return curepig;
	}

	/**
	* Get Task entity by CureTaskCourse
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getCureTaskCourseTask(@PathVariable Integer curetaskcourse_id) {
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id).getTask();
	}

	/**
	* Create a new CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureMethods", method = RequestMethod.POST)
	@ResponseBody
	public CureMethod newCureTaskCourseCureMethods(@PathVariable Integer curetaskcourse_id, @RequestBody CureMethod curemethod) {
		cureTaskCourseService.saveCureTaskCourseCureMethods(curetaskcourse_id, curemethod);
		return cureMethodDAO.findCureMethodByPrimaryKey(curemethod.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newCureTaskCourseTask(@PathVariable Integer curetaskcourse_id, @RequestBody Task task) {
		cureTaskCourseService.saveCureTaskCourseTask(curetaskcourse_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskCourseTask(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_task_id) {
		cureTaskCourseService.deleteCureTaskCourseTask(curetaskcourse_id, related_task_id);
	}

	/**
	* Select an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskCourse loadCureTaskCourse(@PathVariable Integer curetaskcourse_id) {
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id);
	}

	/**
	* View an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureMethods/{curemethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureMethod loadCureTaskCourseCureMethods(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curemethods_id) {
		CureMethod curemethod = cureMethodDAO.findCureMethodByPrimaryKey(related_curemethods_id, -1, -1);

		return curemethod;
	}

	/**
	* Show all CureTaskMethod entities by CureTaskCourse
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureTaskMethods", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskMethod> getCureTaskCourseCureTaskMethods(@PathVariable Integer curetaskcourse_id) {
		return new java.util.ArrayList<CureTaskMethod>(cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id).getCureTaskMethods());
	}

	/**
	* Show all CurePig entities by CureTaskCourse
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/curePigs", method = RequestMethod.GET)
	@ResponseBody
	public List<CurePig> getCureTaskCourseCurePigs(@PathVariable Integer curetaskcourse_id) {
		return new java.util.ArrayList<CurePig>(cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id).getCurePigs());
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveCureTaskCourseTask(@PathVariable Integer curetaskcourse_id, @RequestBody Task task) {
		cureTaskCourseService.saveCureTaskCourseTask(curetaskcourse_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Delete an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskCourse(@PathVariable Integer curetaskcourse_id) {
		CureTaskCourse curetaskcourse = cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse_id);
		cureTaskCourseService.deleteCureTaskCourse(curetaskcourse);
	}

	/**
	* Save an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskCourse saveCureTaskCourse(@RequestBody CureTaskCourse curetaskcourse) {
		cureTaskCourseService.saveCureTaskCourse(curetaskcourse);
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse.getId());
	}

	/**
	* Show all CureTaskCourse entities
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskCourse> listCureTaskCourses() {
		return new java.util.ArrayList<CureTaskCourse>(cureTaskCourseService.loadCureTaskCourses());
	}

	/**
	* View an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureTaskMethods/{curetaskmethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMethod loadCureTaskCourseCureTaskMethods(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curetaskmethods_id) {
		CureTaskMethod curetaskmethod = cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(related_curetaskmethods_id, -1, -1);

		return curetaskmethod;
	}

	/**
	* Delete an existing CurePig entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/curePigs/{curepig_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskCourseCurePigs(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curepigs_id) {
		cureTaskCourseService.deleteCureTaskCourseCurePigs(curetaskcourse_id, related_curepigs_id);
	}

	/**
	* Delete an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureMethods/{curemethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskCourseCureMethods(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curemethods_id) {
		cureTaskCourseService.deleteCureTaskCourseCureMethods(curetaskcourse_id, related_curemethods_id);
	}

	/**
	* Save an existing CurePig entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/curePigs", method = RequestMethod.PUT)
	@ResponseBody
	public CurePig saveCureTaskCourseCurePigs(@PathVariable Integer curetaskcourse_id, @RequestBody CurePig curepigs) {
		cureTaskCourseService.saveCureTaskCourseCurePigs(curetaskcourse_id, curepigs);
		return curePigDAO.findCurePigByPrimaryKey(curepigs.getId());
	}

	/**
	* Create a new CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskCourse newCureTaskCourse(@RequestBody CureTaskCourse curetaskcourse) {
		cureTaskCourseService.saveCureTaskCourse(curetaskcourse);
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse.getId());
	}

	/**
	* Create a new CurePig entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/curePigs", method = RequestMethod.POST)
	@ResponseBody
	public CurePig newCureTaskCourseCurePigs(@PathVariable Integer curetaskcourse_id, @RequestBody CurePig curepig) {
		cureTaskCourseService.saveCureTaskCourseCurePigs(curetaskcourse_id, curepig);
		return curePigDAO.findCurePigByPrimaryKey(curepig.getId());
	}

	/**
	* Save an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureMethods", method = RequestMethod.PUT)
	@ResponseBody
	public CureMethod saveCureTaskCourseCureMethods(@PathVariable Integer curetaskcourse_id, @RequestBody CureMethod curemethods) {
		cureTaskCourseService.saveCureTaskCourseCureMethods(curetaskcourse_id, curemethods);
		return cureMethodDAO.findCureMethodByPrimaryKey(curemethods.getId());
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadCureTaskCourseTask(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Create a new CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureTaskMethods", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMethod newCureTaskCourseCureTaskMethods(@PathVariable Integer curetaskcourse_id, @RequestBody CureTaskMethod curetaskmethod) {
		cureTaskCourseService.saveCureTaskCourseCureTaskMethods(curetaskcourse_id, curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* Save an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureTaskMethods", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMethod saveCureTaskCourseCureTaskMethods(@PathVariable Integer curetaskcourse_id, @RequestBody CureTaskMethod curetaskmethods) {
		cureTaskCourseService.saveCureTaskCourseCureTaskMethods(curetaskcourse_id, curetaskmethods);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethods.getId());
	}

	/**
	* Delete an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskCourse/{curetaskcourse_id}/cureTaskMethods/{curetaskmethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskCourseCureTaskMethods(@PathVariable Integer curetaskcourse_id, @PathVariable Integer related_curetaskmethods_id) {
		cureTaskCourseService.deleteCureTaskCourseCureTaskMethods(curetaskcourse_id, related_curetaskmethods_id);
	}
}